from django.db import models

import markdown
from mdeditor.fields import MDTextField


# Create your models here.
class SupportTopPicture(models.Model):
   
    imgUrl = models.ImageField(upload_to="Support", verbose_name='服务与支持顶部图片')

    class Meta:
        verbose_name = "服务与支持顶部图片"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{:05d}".format(self.id)


class SupportNews(models.Model):
    title = models.CharField( verbose_name='标题', max_length=100)
    synopsis = models.TextField( verbose_name='简介', max_length=100)
    imgUrl = models.ImageField(upload_to="Support", verbose_name='卡片图片')
    create_date = models.DateField(verbose_name='时间', auto_now=False)
    content = MDTextField(verbose_name='markdown')
    content_render = models.TextField( verbose_name='html', null=True, blank=True)

    class Meta:
        verbose_name = "新闻动态"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{:05d}".format(self.id)
    
    def save(self, *args, **kwargs):
        # 将Markdown格式 转为html，页面上显示
        self.content_render = markdown.markdown(
            self.content,
            extensions=[
                'markdown.extensions.extra',
                'markdown.extensions.codehilite',
                'markdown.extensions.toc',
            ]
        )
        super(SupportNews, self).save(*args, **kwargs)


class SupportVideos(models.Model):
    title = models.CharField( verbose_name='标题', max_length=100)
    imgUrl = models.ImageField(upload_to="Support", verbose_name='卡片图片')
    create_date = models.DateField(verbose_name='时间', auto_now=False)
    video_url = models.CharField(verbose_name='视频链接', max_length=2048)

    def __str__(self):
        return "{:05d}".format(self.id)

    class Meta:
        verbose_name = "视频中心"
        verbose_name_plural = verbose_name


class SupportDownloads(models.Model):
    title = models.CharField( verbose_name='标题', max_length=100)
    create_date = models.DateField(verbose_name='时间', auto_now=False)
    file_url = models.CharField(verbose_name='文件链接', max_length=2048)

    def __str__(self):
        return "{:05d}".format(self.id)

    class Meta:
        verbose_name = "资料下载"
        verbose_name_plural = verbose_name